package com.supreme.studyserver.service;

import com.supreme.studyserver.entity.Student;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.cglib.core.ReflectUtils;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

@Service
@Scope(value = BeanDefinition.SCOPE_PROTOTYPE)
public class StudentService {

    private int studentAmount = 0;

    public void addStudentAmount() {
        studentAmount++;
    }

    public void showStudentAmount() {
        System.out.println(studentAmount);
    }

    public void reflectStudent() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, InstantiationException {
        final Student student = new Student();
        student.setName("peter");
        final Method showTeacherName = ReflectUtils.findDeclaredMethod(Student.class, "showName", null);
        showTeacherName.invoke(student);
    }
}
